function lstinf$(a$,b$,c$)
  adra=1:adrb=1:blngt=len(b$):d$=""
  while adrb<=blngt
    if mid$ (a$,adra,1)=mid$ (b$,adrb,1) then:adrb+=1:end if
    adra=adra+1
    end while
  while mid$(a$,adra,1)<>left$(c$,1)
    d$=d$+mid$(a$,adra,1):adra=adra+1
    end while
  lstinf$=d$
  end function

function vldc(a$)
  t0$="!"+a$+".0.0.0."
  t1$=lstinf$(t0$,"!",".")
  t2$=lstinf$(t0$,".",".")
  t3=10^(len(t2$))
  vldc=val(t1$)+(val(t2$)/t3)
  end function

dim chfq[16],chvl[16]

finp$="_.csv"
if argc>2 then:finp$=argv(2):end if

print"56676D20 FFFFFF0F 61010000999E360000000000BF04000004E00C000000"
print"0000000000003C0000000900100000000000000000006801000000000000"
print"000000000000000000000000000000000000000000000000000000000000"
print"000000000000000000000000000000000000000000000000000000000000"
print"000000000000000000000000000000000000000000000000000000000000"
print"000000000000000000000000000000000000000000000000000000000000"
print"000000000000000000000000000000000000000000000000000000000000"
print"000000000000000000000000000000000000000000000000000000000000"
print"000000000000000000000000000000004764332000010000900000004E00"
print"65007700200073006F006E00670000000000000000005300650067006100"
print"20004D00610073007400650072002000530079007300740065006D002000"
print"2F002000470061006D006500200047006500610072000000000000000000"
print"32003000320031002F00310032002F0032003900000053006E0065007600"
print"65006E0054007200610063006B00650072000000000062"

print"508F 503F 509F"
print"50AF 503F 50BF"
print"50CF 503F 50DF"
print"50EF 503F 50FF"



lct=0

open finp$ for input as #1
while eof(1)=0
  file input #1,txrd$
  setcaption("b:"+str$(lct)):lct+=1
  if mid$(txrd$,1,1)="[" then:
    if mid$(txrd$,2,1)="f" then:
      chid=val(mid$(txrd$,3,2))
      chid=chid mod 4 'sn76489 has 4 channels
      chfqv=vldc(lstinf$(txrd$,":","]"))
      chfqv2=int(26.6984611843*2^(8-chfqv))
      if chfqv2>1023 then:chfqv2=1023:end if
      if chfqv2<0 then:chfqv2=0:end if
      chchrfq$=right$("000"+hex$(chfqv2),3)
      txrgo$="50"+right$("0"+hex$(8+2*chid),1)+mid$(chchrfq$,3,1)
      txrgo$+=" 50"+mid$(chchrfq$,1,2)
      print ucase$(txrgo$)
      end if
    if mid$(txrd$,2,1)="v" then:
      chid=val(mid$(txrd$,3,2))
      chid=chid mod 4 'sn76489 has 4 channels
      chvlv=15-(vldc(lstinf$(txrd$,":","]"))*0x10)
      chchrvl$=right$("0"+hex$(chvlv),1)
      txrgo$="50"+right$("0"+hex$(9+chid*2),1)+chchrvl$
      print ucase$(txrgo$)
      end if
    if mid$(txrd$,2,3)="wvb" then:
      wvblv=vldc(lstinf$(txrd$,":","]"))
      wvblv2=wvblv*44100
      wvblv3a=wvblv2 mod 65536
      wvblv3b=int(wvblv2/65536)
      wvblv3as$=ucase$(right$("0000"+hex$(wvblv3a),4))
      for ii=1 to wvblv3b:print"61FFFF":next
      print "61"+mid$(wvblv3as$,3,2)+mid$(wvblv3as$,1,2)
      end if
    end if
  wend
print:print "66":print
close #1


